/**
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * <p>
 * Copyright 2017 © yangxiaobing, 873559947@qq.com
 * <p>
 * This file is part of contentManagerSystem.
 * contentManagerSystem is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * <p>
 * contentManagerSystem is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * <p>
 * You should have received a copy of the GNU Lesser General Public License
 * along with contentManagerSystem.  If not, see <http://www.gnu.org/licenses/>.
 * <p>
 * 这个文件是contentManagerSystem的一部分。
 * 您可以单独使用或分发这个文件，但请不要移除这个头部声明信息.
 * contentManagerSystem是一个自由软件，您可以自由分发、修改其中的源代码或者重新发布它，
 * 新的任何修改后的重新发布版必须同样在遵守GPL3或更后续的版本协议下发布.
 * 关于GPL协议的细则请参考COPYING文件，
 * 您可以在contentManagerSystem的相关目录中获得GPL协议的副本，
 * 如果没有找到，请连接到 http://www.gnu.org/licenses/ 查看。
 * <p>
 * - Author: yangxiaobing
 * - Contact: 873559947@qq.com
 * - License: GNU Lesser General Public License (GPL)
 * - source code availability: http://git.oschina.net/yangxiaobing_175/contentManagerSystem
 */
package com.yxb.cms.domain.vo;

import com.yxb.cms.architect.utils.DateUtil;
import com.yxb.cms.domain.dto.PageDto;
import org.apache.commons.lang3.StringUtils;
import org.nutz.json.Json;
import org.nutz.json.JsonFormat;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 系统日志vo
 * @author yangxiaobing
 * @date 2017/9/6
 *
 */
public class SystemLog extends PageDto implements Serializable {
    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column cc_sys_log.log_id
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    private Integer logId;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column cc_sys_log.log_title
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    private String logTitle;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column cc_sys_log.log_type
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    private String logType;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column cc_sys_log.log_url
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    private String logUrl;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column cc_sys_log.log_method
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    private String logMethod;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column cc_sys_log.log_params
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    private String logParams;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column cc_sys_log.log_exception
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    private String logException;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column cc_sys_log.log_user_name
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    private String logUserName;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column cc_sys_log.log_ip
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    private String logIp;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column cc_sys_log.log_ip_address
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    private String logIpAddress;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column cc_sys_log.log_start_time
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    private Date logStartTime;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column cc_sys_log.log_elapsed_time
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    private Long logElapsedTime;



    /**
     * 查询项
     */
    private String searchTerm;
    /**
     * 查询内容
     */
    private String searchContent;
    private String beginTime;



    public SystemLog() {}

    public SystemLog(String logTitle, String logType, String logUrl, String logMethod, String logUserName, String logIp, Date logStartTime, Long logElapsedTime) {
        this.logTitle = logTitle;
        this.logType = logType;
        this.logUrl = logUrl;
        this.logMethod = logMethod;
        this.logUserName = logUserName;
        this.logIp = logIp;
        this.logStartTime = logStartTime;
        this.logElapsedTime = logElapsedTime;
    }

    public SystemLog(String logTitle, String logType, String logUrl, String logMethod, String logException, String logUserName, String logIp, Date logStartTime, Long logElapsedTime) {
        this.logTitle = logTitle;
        this.logType = logType;
        this.logUrl = logUrl;
        this.logMethod = logMethod;
        this.logException = logException;
        this.logUserName = logUserName;
        this.logIp = logIp;
        this.logStartTime = logStartTime;
        this.logElapsedTime = logElapsedTime;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column cc_sys_log.log_id
     *
     * @return the value of cc_sys_log.log_id
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public Integer getLogId() {
        return logId;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column cc_sys_log.log_id
     *
     * @param logId the value for cc_sys_log.log_id
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public void setLogId(Integer logId) {
        this.logId = logId;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column cc_sys_log.log_title
     *
     * @return the value of cc_sys_log.log_title
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public String getLogTitle() {
        return logTitle;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column cc_sys_log.log_title
     *
     * @param logTitle the value for cc_sys_log.log_title
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public void setLogTitle(String logTitle) {
        this.logTitle = logTitle == null ? null : logTitle.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column cc_sys_log.log_type
     *
     * @return the value of cc_sys_log.log_type
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public String getLogType() {
        return logType;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column cc_sys_log.log_type
     *
     * @param logType the value for cc_sys_log.log_type
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public void setLogType(String logType) {
        this.logType = logType == null ? null : logType.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column cc_sys_log.log_url
     *
     * @return the value of cc_sys_log.log_url
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public String getLogUrl() {
        return logUrl;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column cc_sys_log.log_url
     *
     * @param logUrl the value for cc_sys_log.log_url
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public void setLogUrl(String logUrl) {
        this.logUrl = logUrl == null ? null : logUrl.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column cc_sys_log.log_method
     *
     * @return the value of cc_sys_log.log_method
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public String getLogMethod() {
        return logMethod;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column cc_sys_log.log_method
     *
     * @param logMethod the value for cc_sys_log.log_method
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public void setLogMethod(String logMethod) {
        this.logMethod = logMethod == null ? null : logMethod.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column cc_sys_log.log_params
     *
     * @return the value of cc_sys_log.log_params
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public String getLogParams() {
        return logParams;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column cc_sys_log.log_params
     *
     * @param logParams the value for cc_sys_log.log_params
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public void setLogParams(String logParams) {
        this.logParams = logParams == null ? null : logParams.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column cc_sys_log.log_exception
     *
     * @return the value of cc_sys_log.log_exception
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public String getLogException() {
        return logException;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column cc_sys_log.log_exception
     *
     * @param logException the value for cc_sys_log.log_exception
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public void setLogException(String logException) {
        this.logException = logException == null ? null : logException.trim();
    }


    public String getLogUserName() {
        return logUserName;
    }

    public void setLogUserName(String logUserName) {
        this.logUserName = logUserName;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column cc_sys_log.log_ip
     *
     * @return the value of cc_sys_log.log_ip
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public String getLogIp() {
        return logIp;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column cc_sys_log.log_ip
     *
     * @param logIp the value for cc_sys_log.log_ip
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public void setLogIp(String logIp) {
        this.logIp = logIp == null ? null : logIp.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column cc_sys_log.log_ip_address
     *
     * @return the value of cc_sys_log.log_ip_address
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public String getLogIpAddress() {
        return logIpAddress;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column cc_sys_log.log_ip_address
     *
     * @param logIpAddress the value for cc_sys_log.log_ip_address
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public void setLogIpAddress(String logIpAddress) {
        this.logIpAddress = logIpAddress == null ? null : logIpAddress.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column cc_sys_log.log_start_time
     *
     * @return the value of cc_sys_log.log_start_time
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public Date getLogStartTime() {
        return logStartTime;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column cc_sys_log.log_start_time
     *
     * @param logStartTime the value for cc_sys_log.log_start_time
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public void setLogStartTime(Date logStartTime) {
        this.logStartTime = logStartTime;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column cc_sys_log.log_elapsed_time
     *
     * @return the value of cc_sys_log.log_elapsed_time
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public Long getLogElapsedTime() {
        return logElapsedTime;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column cc_sys_log.log_elapsed_time
     *
     * @param logElapsedTime the value for cc_sys_log.log_elapsed_time
     *
     * @mbggenerated Wed Sep 06 23:14:17 CST 2017
     */
    public void setLogElapsedTime(Long logElapsedTime) {
        this.logElapsedTime = logElapsedTime;
    }

    public String getSearchTerm() {
        return searchTerm;
    }

    public void setSearchTerm(String searchTerm) {
        this.searchTerm = searchTerm;
    }

    public String getSearchContent() {
        return searchContent;
    }

    public void setSearchContent(String searchContent) {
        this.searchContent = searchContent;
    }


    public String getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(String beginTime) {
        this.beginTime = beginTime;
    }

    /**
     * 设置请求参数
     * @param paramMap
     */
    public void setMapToParams(Map<String, String[]> paramMap) {
        if (paramMap == null) {
            return;
        }
        Map<String, Object> params = new HashMap<>();
        for (Map.Entry<String, String[]> param : paramMap.entrySet()) {

            String key = param.getKey();
            String paramValue = (param.getValue() != null && param.getValue().length > 0 ? param.getValue()[0] : "");
            String obj = StringUtils.endsWithIgnoreCase(param.getKey(), "password") ? "" : paramValue;
            params.put(key,obj);
        }
        this.logParams = Json.toJson(params, JsonFormat.compact());
    }

    /**
     * 开始日期格式化
     * @return
     */
    public String getLogStartTime_Lable(){
        if(this.getLogStartTime() != null){
            return DateUtil.Date2Stirng2Second(logStartTime);
        }
        return "";
    }

    /**
     * 日志类型
     * @return
     */
    public String getLogType_Lable(){
        if(null != this.getLogType() &&  ("info").equals(this.getLogType())){
            return "业务日志";
        }else if(null != this.getLogType() &&  ("error").equals(this.getLogType())){
            return "异常日志";
        }else{
            return "";
        }

    }
}